/*********************************************************************
	Rhapsody	: 7.6
	Login		: Pawel
	Component	: DefaultComponent
	Configuration 	: DefaultConfig
	Model Element	: IndoorDisplay
//!	Generated Date	: Sun, 27, Nov 2011 
	File Path	: DefaultComponent/DefaultConfig/CargoLiftSystem/IndoorDisplay.java
*********************************************************************/

package CargoLiftSystem;

//## link itsIDisplay 
import Hardware.IDisplay;
//## auto_generated
import com.ibm.rational.rhapsody.oxf.*;
//## auto_generated
import com.ibm.rational.rhapsody.animation.*;
//## auto_generated
import com.ibm.rational.rhapsody.oxf.states.*;
//## auto_generated
import com.ibm.rational.rhapsody.animcom.animMessages.*;

//----------------------------------------------------------------------------
// CargoLiftSystem/IndoorDisplay.java                                                                  
//----------------------------------------------------------------------------

//## package CargoLiftSystem 


//## class IndoorDisplay 
public class IndoorDisplay implements RiJStateConcept, Animated {
    
    //#[ ignore
    // Instrumentation attributes (Animation)
    private Animate animate;
    
    public static AnimClass animClassIndoorDisplay = new AnimClass("CargoLiftSystem.IndoorDisplay",false);
    //#]
    
    public Reactive reactive;		//## ignore 
    
    /**
     * Zmienna przechowuje pietra wybrane przez podrozujacych winda.
    */
    protected java.util.List selectedFloors;		//## attribute selectedFloors 
    
    protected IDisplay itsIDisplay;		//## link itsIDisplay 
    
    protected Lift itsLift;		//## link itsLift 
    
    //#[ ignore 
    public static final int RiJNonState=0;
    public static final int stopping=1;
    public static final int liftStopped=2;
    public static final int idle=3;
    public static final int floorSelected=4;
    //#]
    protected int rootState_subState;		//## ignore 
    
    protected int rootState_active;		//## ignore 
    
    
    //## statechart_method 
    public RiJThread getThread() {
        return reactive.getThread();
    }
    
    //## statechart_method 
    public void schedTimeout(long delay, long tmID, RiJStateReactive reactive) {
        getThread().schedTimeout(delay, tmID, reactive);
    }
    
    //## statechart_method 
    public void unschedTimeout(long tmID, RiJStateReactive reactive) {
        getThread().unschedTimeout(tmID, reactive);
    }
    
    //## statechart_method 
    public boolean isIn(int state) {
        return reactive.isIn(state);
    }
    
    //## statechart_method 
    public boolean isCompleted(int state) {
        return reactive.isCompleted(state);
    }
    
    //## statechart_method 
    public RiJEventConsumer getEventConsumer() {
        return (RiJEventConsumer)reactive;
    }
    
    //## statechart_method 
    public void gen(RiJEvent event) {
        reactive._gen(event);
    }
    
    //## statechart_method 
    public void queueEvent(RiJEvent event) {
        reactive.queueEvent(event);
    }
    
    //## statechart_method 
    public int takeEvent(RiJEvent event) {
        return reactive.takeEvent(event);
    }
    
    // Constructors
    
    //## auto_generated 
    public  IndoorDisplay(RiJThread p_thread) {
        try {
            animInstance().notifyConstructorEntered(animClassIndoorDisplay.getUserClass(),
               new ArgData[] {
               });
        
        reactive = new Reactive(p_thread);
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## auto_generated 
    public java.util.List getSelectedFloors() {
        return selectedFloors;
    }
    
    //## auto_generated 
    public void setSelectedFloors(java.util.List p_selectedFloors) {
        selectedFloors = p_selectedFloors;
    }
    
    //## auto_generated 
    public IDisplay getItsIDisplay() {
        return itsIDisplay;
    }
    
    //## auto_generated 
    public void setItsIDisplay(IDisplay p_IDisplay) {
        itsIDisplay = p_IDisplay;
        if(p_IDisplay != null)
            {
                animInstance().notifyRelationAdded("itsIDisplay", p_IDisplay);
            }
        else
            {
                animInstance().notifyRelationCleared("itsIDisplay");
            }
    }
    
    //## auto_generated 
    public Lift getItsLift() {
        return itsLift;
    }
    
    //## auto_generated 
    public void __setItsLift(Lift p_Lift) {
        itsLift = p_Lift;
        if(p_Lift != null)
            {
                animInstance().notifyRelationAdded("itsLift", p_Lift);
            }
        else
            {
                animInstance().notifyRelationCleared("itsLift");
            }
    }
    
    //## auto_generated 
    public void _setItsLift(Lift p_Lift) {
        if(itsLift != null)
            {
                itsLift.__setItsIndoorDisplay(null);
            }
        __setItsLift(p_Lift);
    }
    
    //## auto_generated 
    public void setItsLift(Lift p_Lift) {
        if(p_Lift != null)
            {
                p_Lift._setItsIndoorDisplay(this);
            }
        _setItsLift(p_Lift);
    }
    
    //## auto_generated 
    public void _clearItsLift() {
        animInstance().notifyRelationCleared("itsLift");
        itsLift = null;
    }
    
    //## auto_generated 
    public boolean startBehavior() {
        boolean done = false;
        done = reactive.startBehavior();
        return done;
    }
    
    //## ignore 
    public class Reactive extends RiJStateReactive implements AnimatedReactive {
        
        // Default constructor 
        public Reactive() {
            this(RiJMainThread.instance());
        }
        
        
        // Constructors
        
        public  Reactive(RiJThread p_thread) {
            super(p_thread);
            initStatechart();
        }
        
        //## statechart_method 
        public boolean isIn(int state) {
            if(rootState_subState == state)
                {
                    return true;
                }
            return false;
        }
        
        //## statechart_method 
        public boolean isCompleted(int state) {
            return true;
        }
        
        //## statechart_method 
        public void rootState_add(AnimStates animStates) {
            animStates.add("ROOT");
            switch (rootState_subState) {
                case idle:
                {
                    idle_add(animStates);
                }
                break;
                case floorSelected:
                {
                    floorSelected_add(animStates);
                }
                break;
                case stopping:
                {
                    stopping_add(animStates);
                }
                break;
                case liftStopped:
                {
                    liftStopped_add(animStates);
                }
                break;
                default:
                    break;
            }
        }
        
        //## statechart_method 
        public void rootState_entDef() {
            {
                rootState_enter();
                rootStateEntDef();
            }
        }
        
        //## statechart_method 
        public int rootState_dispatchEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            switch (rootState_active) {
                case idle:
                {
                    res = idle_takeEvent(id);
                }
                break;
                case floorSelected:
                {
                    res = floorSelected_takeEvent(id);
                }
                break;
                case stopping:
                {
                    res = stopping_takeEvent(id);
                }
                break;
                case liftStopped:
                {
                    res = liftStopped_takeEvent(id);
                }
                break;
                default:
                    break;
            }
            return res;
        }
        
        //## statechart_method 
        public void stopping_add(AnimStates animStates) {
            animStates.add("ROOT.stopping");
        }
        
        //## statechart_method 
        public void liftStopped_add(AnimStates animStates) {
            animStates.add("ROOT.liftStopped");
        }
        
        //## statechart_method 
        public void idle_add(AnimStates animStates) {
            animStates.add("ROOT.idle");
        }
        
        //## statechart_method 
        public void floorSelected_add(AnimStates animStates) {
            animStates.add("ROOT.floorSelected");
        }
        
        //## auto_generated 
        protected void initStatechart() {
            rootState_subState = RiJNonState;
            rootState_active = RiJNonState;
        }
        
        //## statechart_method 
        public void floorSelectedExit() {
        }
        
        //## statechart_method 
        public void idle_entDef() {
            idle_enter();
        }
        
        //## statechart_method 
        public void idleEnter() {
        }
        
        //## statechart_method 
        public int stoppingTakeNull() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("3");
            stopping_exit();
            liftStopped_entDef();
            animInstance().notifyTransitionEnded("3");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void liftStopped_entDef() {
            liftStopped_enter();
        }
        
        //## statechart_method 
        public void stoppingExit() {
        }
        
        //## statechart_method 
        public void stopping_entDef() {
            stopping_enter();
        }
        
        //## statechart_method 
        public void floorSelectedEnter() {
        }
        
        //## statechart_method 
        public void idle_exit() {
            idleExit();
            animInstance().notifyStateExited("ROOT.idle");
        }
        
        //## statechart_method 
        public void liftStoppedEnter() {
        }
        
        //## statechart_method 
        public void floorSelected_enter() {
            animInstance().notifyStateEntered("ROOT.floorSelected");
            rootState_subState = floorSelected;
            rootState_active = floorSelected;
            floorSelectedEnter();
        }
        
        //## statechart_method 
        public int stopping_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.NULL_EVENT_ID))
                {
                    res = stoppingTakeNull();
                }
            
            return res;
        }
        
        //## statechart_method 
        public int liftStopped_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.NULL_EVENT_ID))
                {
                    res = liftStoppedTakeNull();
                }
            
            return res;
        }
        
        //## statechart_method 
        public int rootState_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            return res;
        }
        
        //## statechart_method 
        public void floorSelected_exit() {
            floorSelectedExit();
            animInstance().notifyStateExited("ROOT.floorSelected");
        }
        
        //## statechart_method 
        public void liftStopped_exit() {
            popNullConfig();
            liftStoppedExit();
            animInstance().notifyStateExited("ROOT.liftStopped");
        }
        
        //## statechart_method 
        public int idleTakeSelectFloor() {
            SelectFloor params = (SelectFloor) event;
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("6");
            idle_exit();
            floorSelected_entDef();
            animInstance().notifyTransitionEnded("6");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void stoppingEnter() {
        }
        
        //## statechart_method 
        public void rootState_enter() {
            animInstance().notifyStateEntered("ROOT");
            rootStateEnter();
        }
        
        //## statechart_method 
        public void rootStateEnter() {
        }
        
        //## statechart_method 
        public int floorSelected_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(SelectFloor.SelectFloor_CargoLiftSystem_id))
                {
                    res = floorSelectedTakeSelectFloor();
                }
            else if(event.isTypeOf(StopImmediately.StopImmediately_CargoLiftSystem_id))
                {
                    res = floorSelectedTakeStopImmediately();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void liftStoppedExit() {
        }
        
        //## statechart_method 
        public void stopping_enter() {
            animInstance().notifyStateEntered("ROOT.stopping");
            pushNullConfig();
            rootState_subState = stopping;
            rootState_active = stopping;
            stoppingEnter();
        }
        
        //## statechart_method 
        public void idle_enter() {
            animInstance().notifyStateEntered("ROOT.idle");
            rootState_subState = idle;
            rootState_active = idle;
            idleEnter();
        }
        
        //## statechart_method 
        public void stopping_exit() {
            popNullConfig();
            stoppingExit();
            animInstance().notifyStateExited("ROOT.stopping");
        }
        
        //## statechart_method 
        public void rootStateEntDef() {
            animInstance().notifyTransitionStarted("0");
            //#[ transition 0 
            selectedFloors = new java.util.LinkedList<java.lang.Integer>();
            //#]
            idle_entDef();
            animInstance().notifyTransitionEnded("0");
        }
        
        //## statechart_method 
        public void liftStopped_enter() {
            animInstance().notifyStateEntered("ROOT.liftStopped");
            pushNullConfig();
            rootState_subState = liftStopped;
            rootState_active = liftStopped;
            liftStoppedEnter();
        }
        
        //## statechart_method 
        public int idle_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(SelectFloor.SelectFloor_CargoLiftSystem_id))
                {
                    res = idleTakeSelectFloor();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void floorSelected_entDef() {
            floorSelected_enter();
        }
        
        //## statechart_method 
        public int liftStoppedTakeNull() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            {
                animInstance().notifyTransitionStarted("5");
                liftStopped_exit();
                floorSelected_entDef();
                animInstance().notifyTransitionEnded("5");
                res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            }
            return res;
        }
        
        //## statechart_method 
        public void rootStateExit() {
        }
        
        //## statechart_method 
        public int floorSelectedTakeStopImmediately() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("2");
            floorSelected_exit();
            stopping_entDef();
            animInstance().notifyTransitionEnded("2");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public int floorSelectedTakeSelectFloor() {
            SelectFloor params = (SelectFloor) event;
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("1");
            floorSelected_exit();
            floorSelected_entDef();
            animInstance().notifyTransitionEnded("1");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void idleExit() {
        }
        
        /**  methods added just for design level debugging instrumentation */
        public boolean startBehavior() {
            try {
              animInstance().notifyBehavioralMethodEntered("startBehavior",
                  new ArgData[] {
                   });
              return super.startBehavior();
            }
            finally {
              animInstance().notifyMethodExit();
            }
        }
        public int takeEvent(RiJEvent event) { 
            try { 
              //animInstance().notifyTakeEvent(new AnimEvent(event));
              animInstance().notifyBehavioralMethodEntered("takeEvent",
                  new ArgData[] { new ArgData(RiJEvent.class, "event", event.toString())
                   });
              return super.takeEvent(event); 
            }
            finally { 
              animInstance().notifyMethodExit();
            }
        }
        /**  see com.ibm.rational.rhapsody.animation.AnimatedReactive interface */
        public AnimInstance animInstance() { 
            return IndoorDisplay.this.animInstance(); 
        }
        
    }
    //#[ ignore
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public AnimClass getAnimClass() { 
        return animClassIndoorDisplay; 
    }
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public Object getFieldValue(java.lang.reflect.Field f, Object userInstance) { 
         Object obj = null;
         try {
             obj = f.get(userInstance);
         } catch(Exception e) {
              System.err.println("Exception: getting Field value: " + e);
              e.printStackTrace();
         }
         return obj;
    }
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public AnimInstance animInstance() {
        if (animate == null) 
            animate = new Animate(); 
        return animate; 
    } 
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public void addAttributes(AnimAttributes msg) {
        
        msg.add("selectedFloors", selectedFloors);
    }
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public void addRelations(AnimRelations msg) {
        
        msg.add("itsLift", false, true, itsLift);
        msg.add("itsIDisplay", false, true, itsIDisplay);
    }
    /** An inner class added as instrumentation for animation */
    public class Animate extends AnimInstance { 
        public  Animate() { 
            super(IndoorDisplay.this); 
        } 
        public void addAttributes(AnimAttributes msg) {
            IndoorDisplay.this.addAttributes(msg);
        }
        public void addRelations(AnimRelations msg) {
            IndoorDisplay.this.addRelations(msg);
        }
        
        public void addStates(AnimStates msg) {
            if ((reactive != null) && (reactive.isTerminated() == false))
              reactive.rootState_add(msg);
        }
        
    } 
    //#]
    
}
/*********************************************************************
	File Path	: DefaultComponent/DefaultConfig/CargoLiftSystem/IndoorDisplay.java
*********************************************************************/

